//获取应用实例(获取app.js全局变量必须获取应用实例)
const App = getApp()

//网络请求封装
import Request_post from "../../../../../request/Request_post"
import Request_get from "../../../../../request/Request_get"

//系统设置项目:(请求地址-在封装中已经引入，这里不需要;   api调用的Appid-partner_app_id;   渠道ID-as_appid)
import config from '../../../../../config/config'; 

//引入时间函数
var dateArray = require("../../../../../utils/CustomFunction/getDayFirstNowLast.js")
var time = require("../../../../../utils/CustomFunction/getNowTime.js")

//引入日期时间：（格式化、反格式化）函数
var formatDate = require("../../../../../utils/CustomFunction/dateFormat.js")
var unformatDate = require("../../../../../utils/CustomFunction/dateUnFormat.js")

Page({

  /**
   * 页面的初始数据
   */
  data: {

    Virtualcard_background:config.imageUrl+"Virtualcard_background.jpg",

    //Title图片的网络地址链接
    Title_Image:config.imageUrl+"title_member_SelfHelpIntegral_MainMenu.jpg",

    scanCode:config.imageUrl+"scanCode.png",
    Camera:config.imageUrl+"Camera.png",
    record:config.imageUrl+"record.png",
    
    //文字框
    text_Frame1:config.imageUrl+"text_Frame1.png",

    vlditgvlu:0

  },

  //Title图片网络外联地址加载失败，则使用本地地址
	bindImgError:function(e){
    this.setData({
      Title_Image: "../../../../../image/title_member_SelfHelpIntegral_MainMenu.jpg"
    })
  },

  camera:function(){
    wx.redirectTo({
      // url:"/SubpkgMemberbiz/pages/Member/MbrRegBind/MbrRegBind?mbrid="+that.data.mbrid+"&mbl="+that.data.mbl //带参数跳转页面
      url: "/SubpkgMemberbiz/pages/Member/Mbritgextadd/TakePictureItg/TakePictureItg"
    })
  },

  itgRecord:function(){
    wx.redirectTo({
      url: '/SubpkgMemberbiz/pages/Member/Mbritgextadd/ItgAdd_Record/ItgAdd_Record',
    })
  },

  scanCode:function(){
    var that = this

    // 会员是否注册的标志regflg === 'n'时，路由到引导注册页面
		getApp().loginPromise.then(v => {	//app.js的Promise成功回调（全局变量赋值成功后才执行请求）
			if(App.globalData.regflg === 'n'){
				wx.redirectTo({
				  url: '/pages/Public/boot_regstration/boot_regstration',
				})
				return;
			}else{
        wx.scanCode({   //调用微信扫一扫
          onlyFromCamera:false,
          scanType:['qrCode','barCode'],
          success: (res) => {
            if(res.errMsg == "scanCode:ok"){
              that.setData({
                QR_CODE:res.result
              })
               //网络请求-Api：H01-会员积分补登申请-02扫码
               /** Api请求：  **/
               Request_post.post(
                config.domainName+"api_wxmkt_server/mbritgextadd/mbritgextadd",
                {
                  "rqtmodid": "02",
                  "qrcode": that.data.QR_CODE
                },
                function(res){
                  if(res.return_no == 1){  //调用成功
                    that.setData({
                      rqtno:res.return_data.rqtno
                    })
                    wx.redirectTo({
                      url: "/SubpkgMemberbiz/pages/Member/Mbritgextadd/ItgAdd_RecordDetails/ItgAdd_RecordDetails?rqtno="+that.data.rqtno
                    })
                  }else{   //调用接口不成功
                    wx.showModal({
                      content: res.return_msg,
                      showCancel:false,
                    })
                  }
                }
              )   
            }
            // console.log(res)
          }
        })
      }
		})

    
  },

  //未注册会员点击注册
  regNow:function(){
    wx.redirectTo({ 
      url:"/SubpkgPublicPage/pages/PublicPage/PrivacyPolicy/PolicyMain/PolicyMain"
    });
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this

    // 会员是否注册的标志regflg
    getApp().loginPromise.then(v => {	//app.js的Promise成功回调（全局变量赋值成功后才执行请求）
      this.setData({regflg: App.globalData.regflg})
      // console.log(App.globalData.regflg)
    })
    
    // 获取 是否启用CSS页面动画的判断参数
    that.setData({
			BubbleAnimationShow: wx.getStorageSync('StrMktopt').BubbleAnimationShow
		})

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    /** Api请求：04-001 会员信息查询（验证已绑定）  **/
    getApp().loginPromise.then(v => {	//app.js的Promise成功回调（全局变量赋值成功后才执行请求）
      Request_get.get(
        config.domainName+"api_wxmkt_server/mbrreg/findwxmbr",
        {},
        function(res){
          if(res != "undefined" &&　res.return_no == 1){
            
            wx.setStorageSync('StrMbrInfo', res.return_data)
            let StrMbrInfo = wx.getStorageSync('StrMbrInfo')
            that.setData({
              mbl: StrMbrInfo.mbl,
              mbrclsdes: StrMbrInfo.mbrclsdes,
              sumitgvlu: StrMbrInfo.sumitgvlu,
              vlditgvlu: StrMbrInfo.vlditgvlu,
              cardno:  StrMbrInfo.cardno,
            })
          }else{
            that.setData({vlditgvlu:0}
          )}
        }
      )
    })

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})